package com.stone.sys.action;

/**
 * <pre>
 * 日志查询Action
 * @author jz
 * </pre>
 */

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.stone.common.action.AdvanceSearchJsonUtils;
import com.stone.sys.pojo.TCydy;
import com.stone.sys.pojo.TCydyType;
import com.stone.sys.service.DictionaryService;
import com.stone.utils.StringUtils;

import frm.ssh.action.BaseListAction;

public class CydyListAction extends BaseListAction {

	private static final long serialVersionUID = 3979577965804736350L;

	private DictionaryService dicService;
	
	public DictionaryService getDicService() {
		return dicService;
	}

	public void setDicService(DictionaryService dicService) {
		this.service = dicService;
		this.dicService = dicService;
	}
	
    /** * 构造方法. */
    public CydyListAction() {
        this.entityClass = TCydy.class;
    }

	/**
	 * 设置查询条件
	 */
	public HashMap<String, Object> setSearchCondition() {
		
		HashMap<String, Object> m = new HashMap<String, Object>();
		
		List<Object> valsList = new ArrayList<Object>();
		
		m.put("cols", "dic");
		
		String conditions = " dic.dytype = '" + super.getSearchBean().getCon1() + "'";

		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon2())) {
			conditions += " and dic.dycode like ?";
			valsList.add("%" + super.getSearchBean().getCon2() + "%");
		//	conditions += " and dic.itemId like '%" + super.getSearchBean().getCon2() + "%'";
		}
		
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon3())) {
			conditions += " and dic.dyname like ?";
			valsList.add("%" + super.getSearchBean().getCon3() + "%");
			//conditions += " and dic.itemName like '%" + super.getSearchBean().getCon3() + "%'";
		}
		
		// 高级查询设置
		try {
			if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getConAdvance())) {
				HashMap<String,Object> rtnMap = AdvanceSearchJsonUtils.jsonToList(super.getSearchBean().getConAdvance());
				conditions += rtnMap.get("conditions");
				valsList.addAll((List<Object>)rtnMap.get("vals"));
			}	
		} catch (Exception e) {
			
		}
		
		// 查询条件
		m.put("conditions",conditions);
		m.put("clause", " order by dic.sortid");
		m.put("alias", "dic");
		m.put("vals", valsList.toArray());
		
		dicList = dicService.findListByHql( " from TCydyType order by sortid");
		
		return m;
		
	}
	
	private List<TCydyType> dicList;


	public List<TCydyType> getDicList() {
		return dicList;
	}
}
